import { defineStore } from "pinia";

interface GuageType {
  eiid: number;
  isTest: boolean;
}
interface ExamGaugeState {
  eid: number;
  question_count: number;
  gauge: GuageType[];
  answer_num: number;
}
// eslint-disable-next-line ts/consistent-type-definitions
type ExamGaugeGetter = {
  allCombo: (store: ExamGaugeState) => boolean;
};
interface ExamGaugeAction {
  init: (eid: number, question_count: number) => void;
  answerThat: (eiid: number) => void;
}
export const useMyExamGaugeStore = defineStore<"myExamGaugeStore", ExamGaugeState, ExamGaugeGetter, ExamGaugeAction>({
  id: "myExamGaugeStore",
  state: () => ({
    eid: 0,
    question_count: 0,
    gauge: [],
    answer_num: 0,
  }),
  getters: {
    allCombo: store => store.answer_num === store.question_count,
    
  },
  actions: {
    init(eid: number, question_count: number) {
      this.eid = eid;
      this.question_count = question_count;
      this.gauge = Array.from({ length: question_count }, (_, i) => ({
        eiid: i,
        isTest: false,
      }));
    },
    answerThat(eiid: number) {
      for (const item of this.gauge) {
        if (item.eiid === eiid) {
          item.isTest = true;
          this.answer_num++;
          break;
        }
      }
    },
  },
});
